<div class="nav-sub w1180">
	<ul class="zoom">
		<li><a class="on" href="">新增溯源</a></li>
		<li><a href="/crm/material/catelog-list">溯源类型列表</a></li>
		<li><a href="/crm/material/cate-list">溯源类目列表</a></li>
		<li><a href="/crm/material/list">溯源列表</a></li>
		<li><a href="/crm/material/report-list">溯源报告列表</a></li>
	</ul>
</div>
<div class="main-ct w1180">
	<a href="javascript:history.go(-1);" class="btn-cs btn-blue btn-fillet mt10">返 回</a>
	<form id="commonForm" method="post" action="/crm/material/insert">
		<div class="form-info mt20">

			<dl>
				<dt>溯源类目：</dt>
				<dd>
					<select name="material_category_id" id="material_category_id">
    				<?php if ($this->cate):?>
    				<?php foreach ($this->cate as $k=>$v):?>
        				<option value="<?php echo $v['material_category_id']; ?>"><?php echo $v['material_category_name']; ?></option>
        			<?php endforeach; ?>
        			<?php else:?>
        				<option value="">请选择</option>
    				<?php endif;?>
    			</select>
				</dd>
			</dl>
			<dl>
				<dt>商品：</dt>
				<dd>
					<select name="product_id" id="product_id">
					<?php if ($this->product):?>
    				<?php foreach ($this->product as $k=>$v):?>
        				<option value="<?php echo $v['product_id']; ?>"><?php echo $v['product_name']; ?></option>
        			<?php endforeach; ?>
        			<?php else:?>
        				<option value="">请选择</option>
    				<?php endif;?>
    			</select>
				</dd>
			</dl>
			<dl>
				<dt>材源代码：</dt>
				<dd>
					<input type="text" class="txt" name="material_code"
						id="material_code">
				</dd>
			</dl>
			<dl>
				<dt>材料名称：</dt>
				<dd>
					<input type="text" class="txt" name="material_name"
						id="material_name">
				</dd>
			</dl>
			<!-- 
			<dl>
				<dt>源头：</dt>
				<dd>
					<input type="text" class="txt" name="original" id="original">
				</dd>
			</dl>
			<dl>
				<dt>简介：</dt>
				<dd>
					<textarea name="description" id="description"></textarea>
				</dd>
			</dl>
			<dl>
				<dt>生产流程：</dt>
				<dd>
					<textarea name="workflow" id="workflow"></textarea>
				</dd>
			</dl>
			<dl>
				<dt>特点：</dt>
				<dd>
					<input type="text" class="txt" name="feature" id="feature">
				</dd>
			</dl>
			<dl>
				<dt>联系方式：</dt>
				<dd>
					<input type="text" class="txt" name="contact" id="contact">
				</dd>
			</dl>
			<dl>
				<dt>地址：</dt>
				<dd>
					<input type="text" class="txt" name="address" id="address">
				</dd>
			</dl>
			  -->
			<dl>
				<dt>供应商：</dt>
				<dd>
					<input type="text" class="txt" name="material_supplier">
				</dd>
			</dl>
						
			<dl>
    			<dt>商户资质（营业执照）：</dt>			
    			<dd class="goods-list">
    				<div class="goods-img goods-img-add">
    				
    					<div class="g-img-ct"  id="cover-material_supplier_img1">
    						<img src="/images/ico/ico-add.png"  id="add-material_supplier_img1">
    						<input type="hidden" name="material_supplier_img1" id="material_supplier_img1">
    					</div>
    					
    					<label class="tips">图片尺寸：** * **</label>
    					<a href="javascript:;" class="btn-del" id="del-material_supplier_img1" style="display:none"></a>
    					
    				</div>
    			</dd>
			</dl>
		
		
			<dl>
    			<dt>商户资质（食品流通许可证）：</dt>			
    			<dd class="goods-list">
    				<div class="goods-img goods-img-add">
    					<div class="g-img-ct"  id="cover-material_supplier_img2">
    						<img src="/images/ico/ico-add.png"  id="add-material_supplier_img2">
    						<input type="hidden" name="material_supplier_img2" id="material_supplier_img2">
    					</div>
    					<a href="javascript:;" class="btn-del" id="del-material_supplier_img2" style="display:none"></a>
    				</div>
    			</dd>
			</dl>
			
			
<!-- 			<dl> -->
<!--     			<dt>商户资质（食品流通许可证）：</dt> -->
<!--     			<dd class="goods-list" id="show-supplier-img2"> -->
<!--     				<div class="goods-img supplier-img2-add"> -->
<!--     					<div class="g-img-ct"  id="supplier2"> -->
<!--     						<img src="/images/ico/ico-add.png"> -->
<!--     					</div> -->
<!--     				</div> -->
<!--     			</dd> -->
<!-- 			</dl> -->
			
<!-- 			<dl> -->
<!--     			<dt>商户资质（全国工业产品生产许可证）：</dt> -->
<!--     			<dd class="goods-list" id="show-supplier-img3"> -->
<!--     				<div class="goods-img supplier-img3-add"> -->
<!--     					<div class="g-img-ct"  id="supplier3"> -->
<!--     						<img src="/images/ico/ico-add.png"> -->
<!--     					</div> -->
<!--     				</div> -->
<!--     			</dd> -->
<!-- 			</dl> -->
			
			<dl>
    			<dt>商户资质（全国工业产品生产许可证）：</dt>			
    			<dd class="goods-list">
    				<div class="goods-img goods-img-add">
    					<div class="g-img-ct"  id="cover-material_supplier_img3">
    						<img src="/images/ico/ico-add.png"  id="add-material_supplier_img3">
    						<input type="hidden" name="material_supplier_img3" id="material_supplier_img3">
    					</div>
    					<a href="javascript:;" class="btn-del" id="del-material_supplier_img3" style="display:none"></a>

    				</div>
    			</dd>
			</dl>
			
			
			
			<dl>
				<dt>生产日期：</dt>
				<dd>
					<input type="text" class="txt" name="material_production_date" onFocus="WdatePicker({isShowClear:false,readOnly:true})">
				</dd>
			</dl>
			
			<dl>
				<dt>生产商/地：</dt>
				<dd>
					<input type="text" class="txt" name="material_yieldly">
				</dd>
			</dl>
			
			<dl>
				<dt>批次：</dt>
				<dd>
					<input type="text" class="txt" name="material_batch_no">
				</dd>
			</dl>
			
			<dl>
				<dt>保质期：</dt>
				<dd>
					<input type="text" class="txt" name="material_expiry_date" onFocus="WdatePicker({isShowClear:false,readOnly:true})">
				</dd>
			</dl>
			
			<dl>
				<dt>其它：</dt>
				<dd>
					<textarea type="text" class="txt" name="material_other"></textarea>
				</dd>
			</dl>
			
			<dl>
    			<dt>材料展示（图片）：</dt>
    			<dd class="goods-list" id="show-material_img">
    				<div class="goods-img  goods-img-add">
    					<div class="g-img-ct"  id="cover_material_img">
    						<img src="/images/ico/ico-add.png">
    					</div>
    				</div>
    			</dd>
			</dl>
			<dl class="tips-line"><dt>&nbsp;</dt><dd>材料展示图片尺寸：** * **</dd></dl>
			
		</div>
		<p class="mt30 txt-center">
			<input class="input-cs btn-fillet btn-green" type="submit" value="确定" />
			<input class="input-cs btn-fillet mr20" type="reset" value="取消" />
		</p>
	</form>
</div>
<script src="/plugins/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="/plugins/webUpload/webuploader.js"></script>
<script>


var uploader1 = WebUploader.create({
	// 选完文件后，是否自动上传。
	fileNumLimit: 1,
	auto: true,
	duplicate:1,
	swf:'/plugins/webUpload/Uploader.swf',
	server: '/crm/shop/ajax-upload',
	pick: {
		id:'#cover-material_supplier_img1',
		multiple:false
	},
	formData :{
		path:"/material/supplier",
	},
	method :'post',
	accept: {
		title: 'Images',
		extensions: 'gif,jpg,jpeg,png',
		mimeTypes: 'image/*'
	}
});


uploader1.on('uploadSuccess',function(file,response){
	if(response.state == 'SUCCESS'){
// 	var html='';
// 	html +=	'<div class="goods-img">'
// 				+ '<div class="g-img-ct">'
// 			    + '<img src="'+ response.url +'">'
// 			    + '<input type="hidden" name="'+ file.id +'" id="org_logo1" value="'+ response.url +'">'
// 				+ '</div>'
// 				+ '<a class="btn-del" href="javascript:delImg();"></a>'
// 				+ '</div>';
// 	$('#show-supplier-img1').append(html);

		$('#add-material_supplier_img1').attr("src",response.url);
 		$('#material_supplier_img1').val(response.url);
 		//$('#del-material_supplier_img1').show();
		
	}
});


var uploader2 = WebUploader.create({
	// 选完文件后，是否自动上传。
	fileNumLimit: 1,
	auto: true,
	duplicate:1,
	swf:'/plugins/webUpload/Uploader.swf',
	server: '/crm/shop/ajax-upload',
	pick: {
		id:'#cover-material_supplier_img2',
		multiple: false
	},
	formData :{
		path:"/material/supplier",
	},
	method :'post',
	accept: {
		title: 'Images',
		extensions: 'gif,jpg,jpeg,png',
		mimeTypes: 'image/*'
	}
});


uploader2.on('uploadSuccess',function(file,response){
	if(response.state == 'SUCCESS'){
// 	var html='';
// 	html +=	'<div class="goods-img">'
// 				+ '<div class="g-img-ct">'
// 			    + '<img src="'+ response.url +'">'
// 			    + '<input type="hidden" name="'+ file.id +'" id="org_logo1" value="'+ response.url +'">'
// 				+ '</div>'
// 				+ '<a class="btn-del" href="javascript:delImg();"></a>'
// 				+ '</div>';
// 	$('#show-supplier-img1').append(html);

		$('#add-material_supplier_img2').attr("src",response.url);
 		$('#material_supplier_img2').val(response.url);
 		//$('#del-material_supplier_img1').show();
		
	}
});



var uploader3 = WebUploader.create({
	// 选完文件后，是否自动上传。
	fileNumLimit: 1,
	auto: true,
	duplicate:1,
	swf:'/plugins/webUpload/Uploader.swf',
	server: '/crm/shop/ajax-upload',
	pick: {
		id:'#cover-material_supplier_img3',
		multiple:false
	},
	formData :{
		path:"/material/supplier",
	},
	method :'post',
	accept: {
		title: 'Images',
		extensions: 'gif,jpg,jpeg,png',
		mimeTypes: 'image/*'
	}
});


uploader3.on('uploadSuccess',function(file,response){
	if(response.state == 'SUCCESS'){
// 	var html='';
// 	html +=	'<div class="goods-img">'
// 				+ '<div class="g-img-ct">'
// 			    + '<img src="'+ response.url +'">'
// 			    + '<input type="hidden" name="'+ file.id +'" id="org_logo1" value="'+ response.url +'">'
// 				+ '</div>'
// 				+ '<a class="btn-del" href="javascript:delImg();"></a>'
// 				+ '</div>';
// 	$('#show-supplier-img1').append(html);

		$('#add-material_supplier_img3').attr("src",response.url);
 		$('#material_supplier_img3').val(response.url);
 		//$('#del-material_supplier_img1').show();
		
	}
});


//素材商品上传

var materialUploader = WebUploader.create({
	// 选完文件后，是否自动上传。
	fileNumLimit: 8,
	auto: true,
	duplicate:1,
	swf:'/plugins/webUpload/Uploader.swf',
	server: '/crm/shop/ajax-upload',
	pick: {
		id:'#cover_material_img',
		multiple:true
	},
	formData :{
		path:"/material/material",
	},
	method :'post',
	accept: {
		title: 'Images',
		extensions: 'gif,jpg,jpeg,png',
		mimeTypes: 'image/*'
	}
});


materialUploader.on('uploadSuccess',function(file,response){
	if(response.state == 'SUCCESS'){
	var html='';
	html +=	'<div class="goods-img">'
				+ '<div class="g-img-ct">'
			    + '<img src="'+ response.url +'">'
			    + '<input type="hidden" name="'+ file.id +'" value="'+ response.url +'">'
				+ '</div>'
				+ '<a class="btn-del" href="javascript:delImg();"></a>'
				+ '</div>';
	$('#show-material_img').append(html);
		
	}
});



$(function(){
$(".btn-del").click(function() {
	 $(this).parent("div").remove(); 
});
});

function delImg(){

	$(".btn-del").click(function() {
    	 $(this).parent("div").remove(); 
     });
	
}

	$().ready(function() {
		$("#commonForm").validate({
			debug:true,
			rules: {
				material_category_id: {
					required: true,
				},
				product_id: {
					required: true,
				},
				material_code: {
					required: true,
				},
				material_name: {
					required: true,
				},
				material_supplier: {
					required: true,
				},
				material_production_date: {
					required: true,
				},
				material_yieldly: {
					required: true,
				},
				material_batch_no: {
					required: true,
				},
				material_expiry_date: {
					required: true,
				},
				material_expiry_date: {
					required: true,
				},
		
			},
    		submitHandler:function(form){ 
    	            form.submit();
    	    }   
		});

	});
</script>